package com.wtwd.campus;

import com.wtwd.campus.attendancenetty.AttendanceNettyServer;
import com.wtwd.campus.encryptnetty.EncryptNettyServer;
import com.wtwd.campus.netty.NettyServer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.cloud.openfeign.EnableFeignClients;

import java.net.InetSocketAddress;


/**
 * @Author ldaoliang
 * @Date create in 12:13 2021/4/20
 * @Description
 */
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class})
@EnableEurekaClient
@EnableFeignClients
public class NettyApplication implements CommandLineRunner{

    @Value("${netty.port}")
    private int port;
    @Value("${encrypt.port}")
    private int encryptPort;
    @Value("${netty.url}")
    private String url;
    // TODO 配置文件添加对应port参数
    @Value("${attendance.port}")
    private int attendancePort;

    @Autowired
    private NettyServer server;
    @Autowired
    private EncryptNettyServer encryptNettyServer;
    @Autowired
    private AttendanceNettyServer attendanceNettyServer;


    @Override
    public void run(String... args) throws Exception {
        InetSocketAddress address = new InetSocketAddress(url,port);
        System.out.println("run  .... . ... "+url);
        server.start(address);
        InetSocketAddress inetSocketAddress = new InetSocketAddress(url, encryptPort);
        System.out.println("加密Socket服务.......run");
        encryptNettyServer.start(inetSocketAddress);
        InetSocketAddress attendanceAddress = new InetSocketAddress(url, attendancePort);
        attendanceNettyServer.start(attendanceAddress);
    }

    public static void main(String[] args) {
        SpringApplication.run(NettyApplication.class,args);
    }


}

